package com.nbgs.demo.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nbgs.demo.controller.form.BillMessage;
import com.nbgs.demo.model.WaterBill;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface WaterBillMapper {
    //根据区域号查询账单
    @Select("<script>\n" +
            "SELECT\n" +
            "t_consumption.consumption_month,\n" +
            "t_consumption.consumption_start,\n" +
            "t_consumption.consumption_end,\n" +
            "t_waterbill.consumption_volume,\n" +
            "t_waterbill.bill_id,\n" +
            "t_area.area_name,\n" +
            "t_waterbill.bill_state,\n" +
            "t_waterbill.payable,\n" +
            "t_waterbill.overdue\n" +
            "FROM t_consumption \n" +
            "LEFT JOIN t_card\n" +
            "ON\n" +
            "t_consumption.card_id=t_card.card_id\n" +
            "LEFT JOIN t_waterbill\n" +
            "ON \n" +
            "t_waterbill.card_id=t_consumption.card_id\n" +
            "LEFT JOIN t_area\n" +
            "ON t_card.area_num=t_area.area_num\n" +
            "<where>\n" +
            "<if test=\"areaName!=null and areaName!=''\">\n" +
            " and t_area.area_name=#{areaName}\n" +
            "</if>\n" +
            "</where>\n" +
            "order by bill_id desc\n" +
            "</script>\n")
    IPage<BillMessage> showSum(Page<BillMessage> page,@Param("areaName") String areaName);
    //查询总条数
    @Select("<script>\n" +
            "SELECT\n" +
            "count(*)\n" +
            "FROM t_consumption \n" +
            "LEFT JOIN t_card\n" +
            "ON\n" +
            "t_consumption.card_id=t_card.card_id\n" +
            "LEFT JOIN t_waterbill\n" +
            "ON \n" +
            "t_waterbill.card_id=t_consumption.card_id\n" +
            "LEFT JOIN t_area\n" +
            "ON t_card.area_num=t_area.area_num\n" +
            "<where>\n" +
            "<if test=\"areaName!=null and areaName!=''\">\n" +
            "  t_area.area_name=#{areaName}\n" +
            "</if>\n" +
            "</where>\n" +
            "order by bill_id desc\n" +
            "</script>\n")
    int getTotal(@Param(value="areaName") String areaName);
}
